import request from '@/service/request';
import { IQSDetail, IQSTableInfo, IQSListDetail, IQsListCount } from './types';

// 分页请求问卷列表
export function requestQsListByPage(data: { pageNum: number; pageSize: number }) {
  return request.post<IQSTableInfo>({
    url: '/qsList/getQsListByPage',
    data,
    interceptors: {
      responseInterceptor(res: any): IQSTableInfo {
        return res?.data;
      },
    },
  });
}

// 保存问卷,传入问卷id则修改已有问卷,不传入id则新建一个问卷
export function requestSaveQsList(data: IQSDetail) {
  return request.post({
    url: '/qsList/saveQsList',
    data,
    headers: { 'Content-Type': 'application/json' },
  });
}

// 提交问卷(将问卷状态修改为待审核)
// export function requestCommitQsList(data: IQSDetail) {
//   return request.post({
//     url: '/qsList/commitQs',
//     data,
//     headers: { 'Content-Type': 'application/json' },
//   });
// }

// 根据问卷id获取问卷
export function requestQsList(id: number) {
  return request.get<IQSDetail>({
    url: `/qsList/${id}`,
    interceptors: {
      responseInterceptor(res: any): IQSDetail {
        return res?.data;
      },
    },
  });
}

// 根据问卷id删除问卷
export function requestDeleteQsList(id: number) {
  return request.delete({
    url: `/qsList/${id}`,
  });
}

// 问卷细节处理-答案,标记,流转,留言
export function requestAddQsDetail(data: IQSListDetail) {
  return request.post({
    url: '/qsDetail/addDetail',
    data,
  });
}

// 问卷细节处理-根据type来查询datail
export function requestQsDetail(params: IQSListDetail) {
  return request.get<IQSListDetail>({
    url: '/qsDetail/getDetail',
    params,
    interceptors: {
      responseInterceptor(res: any): IQSListDetail {
        return res?.data[0];
      },
    },
  });
}

// 问卷细节处理-根据id来删除detail
export function requestDeleteQsDetail(id: number) {
  return request.delete({
    url: `/qsDetail/${id}`,
  });
}
// 问卷细节处理-根据id来删除detail
export function requestBatchDeleteQsDetail(ids: any) {
  return request.post({
    url: `/qsList/batchDelete?ids=${ids}`,
  });
}

// 发送提醒
export function requestSendRemind(data: { ids: number[] }) {
  return request.post<string>({
    url: '/qsList/sendReminder',
    data,
    interceptors: {
      responseInterceptor(res: any): string {
        return res;
      },
    },
  });
}

// 各种待办的状态数量
export function requestQsListCount() {
  return request.get<IQsListCount>({
    url: '/qsList/getMyToDoQsList',
    interceptors: {
      responseInterceptor(res: any): IQsListCount {
        return res?.data;
      },
    },
  });
}
